package com.whosly.rapid.data.resp.pojo.response;

import java.io.Serializable;

import com.whosly.api.constant.Constants;
import com.whosly.rapid.lang.mask.instance.AbstractMaskBo;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * REST请求的基础请求返回实体统一接口类
 *
 * @author 袁洋 2014年9月18日
 */
@JsonIgnoreProperties(value = { "serialVersionUID" })
public class BaseResponse extends AbstractMaskBo implements Serializable {
	/**
	 *
	 */
	private static final long serialVersionUID = -7258009802898919035L;

	/** 结果码 */
	@Getter
	@Setter
	private String code = Constants.SUCCESS;
	/** 结果描述 */
	@Getter
	@Setter
	private String message = "";

	public BaseResponse() {
		//.
	}

	public BaseResponse(String code, String message) {
		this.code = code;
		this.message = message;
	}

	/**
	 * @return 请求是否成功
	 */
	public boolean isSuccess() {
		if (StringUtils.equals(Constants.SUCCESS, this.code)) {
			return true;
		}
		return false;
	}

	public static BaseResponse success() {
		return success(null);
	}

	public static BaseResponse success(String message) {
		return new BaseResponse(Constants.SUCCESS, message);
	}

	public static BaseResponse failure(String code, String message) {
		return new BaseResponse(code, message);
	}

}
